home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15548 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  62 lines

  1. Path: grimsel.zurich.ibm.com!usenet
  2. From: wgk@zurich.ibm.com (Keith Whittingham)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Null Pointer Assignment error
  5. Date: 6 Apr 1996 12:47:07 GMT
  6. Organization: IBM Research, ZRH
  7. Message-ID: <4k5p4b$tds@grimsel.zurich.ibm.com>
  8. References: <4k5g19$84a@newsgate.dircon.co.uk>
  9. Reply-To: wgk@zurich.ibm.com
  10. NNTP-Posting-Host: pine.zurich.ibm.com
  11. X-Newsreader: IBM NewsReader/2 v1.00
  12.  
  13. In <4k5g19$84a@newsgate.dircon.co.uk>, dalim2@dircon.co.uk (Keith George) writes:
  14. >I get a Null pointer Assignment Error 'What is it?'
  15. >
  16. >I'm using Turbo C++ 3.0 to test a String class that I am trying to 
  17. >understand copied from an "Understanding C++" book!
  18. >
  19. >The Turbo C++ help pages seem very brief!
  20. >
  21. >How can I track down this error ?
  22. >Why does it not happen in the large memory model?
  23. >
  24. >many regards
  25. >    keith george
  26.  
  27.  
  28. You've assigned something to a NULL pointer:
  29.  
  30. int *ptr;
  31.  
  32. main()
  33. {
  34.   *ptr = 1234;
  35. }
  36.  
  37. ptr is a pointer to an integer and does not (in the example) have any memory
  38. to store anything in it. The way it's been defined assigns the value
  39. zero to this pointer (under most compilers (sic)). The line of code
  40. then writes the value 1234 to the address pointed to by ptr - e.g. 0.
  41.  
  42. The compiler checks this by keeping a checksum of the first 32 bytes or
  43. so of memory at offset 0 in the data segment. If these are corrupted 
  44. (they should never change) then it is reported to you at the end of
  45. the program run.
  46.  
  47. Unfortunatly this check cannot be done in the large mode as 0x000:0x0000
  48. in the Intel architecture is the interrupt table and is subject to change
  49. during program runs.
  50.  
  51. You need to be very careful when using pointers as Borland can only check
  52. for bad pointer assignement when the pointer has a value of 0.
  53.  
  54. Borland debugger has a "breakpoint on changed memory global" option which
  55. if you set it to look at 0 for 16 odd bytes it will find the erroneous
  56. line of code - the program runs slowly though.
  57.  
  58. Keith
  59.  
  60.  
  61.  
  62.